package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.Models.Article;
import com.lzw.bluetoothpractice.Models.Forum;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.bean.Messages;
import com.lzw.bluetoothpractice.bean.UserDoctorMessageBean;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.newim.bean.BmobIMMessage;

public class SendAdapter extends RecyclerView.Adapter<SendAdapter.ViewHolder> {

    private List<UserDoctorMessageBean.DataBean> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<UserDoctorMessageBean.DataBean> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }
    public SendAdapter(Context mcontext) {
        this.mcontext = mcontext;

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        UserDoctorMessageBean.DataBean messages=datas.get(position);
        if(messages.getMesType().equals("0")){
            Glide.with(mcontext).load(AppConfig.BASE_URL+messages.getUserPic()).into(holder.iv_head);

            holder.tv_message.setText(messages.getMesContent());
            holder.iv_head1.setVisibility(View.GONE);
            holder.tv_message1.setVisibility(View.GONE);
        }else {
            Glide.with(mcontext).load(AppConfig.BASE_URL+messages.getDoctorPic()).into(holder.iv_head1);

            holder.tv_message1.setText(messages.getMesContent());
            holder.iv_head.setVisibility(View.GONE);
            holder.tv_message.setVisibility(View.GONE);
        }


    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.item_text_send,parent,false);

        return new ViewHolder(itemView);
    }

    public void Add(UserDoctorMessageBean.DataBean message){
        datas.add(message);
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        View view;

        ImageView iv_head;
        TextView tv_message;
        ImageView iv_head1;
        TextView tv_message1;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view=itemView;

            iv_head1=view.findViewById(R.id.chat_item_header1);
            tv_message1=view.findViewById(R.id.chat_item_content_text1);
            iv_head=view.findViewById(R.id.chat_item_header);
            tv_message=view.findViewById(R.id.chat_item_content_text);

        }
    }
}
